package com.easypay.reactive8583;

import lombok.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author pandans
 * @date 2021/03/04 14:46
 * @Description:
 */
@NoArgsConstructor
@Data
public abstract class ConnectorConfiguration {
    private static final int DEFAULT_IDLE_TIMEOUT_SECONDS = 30;
    private static final int DEFAULT_MAX_FRAME_LENGTH = 8192;
    private static final int DEFAULT_FRAME_LENGTH_FIELD_LENGTH = 2;
    private static final int DEFAULT_FRAME_LENGTH_FIELD_ADJUST = 0;
    private static final int DEFAULT_FRAME_LENGTH_FIELD_OFFSET = 0;

    private boolean addEchoMessageListener;

    /**
     * The maximum length of the frame.
     */
    private Integer maxFrameLength = DEFAULT_MAX_FRAME_LENGTH;

    /**
     * Set channel read/write idle timeout in seconds.
     *
     * If no message was received/sent during specified time interval then `Echo` message will be sent.
     *
     * @return timeout in seconds
     */
    private Integer idleTimeout = DEFAULT_IDLE_TIMEOUT_SECONDS;

    /**
     * Returns number of threads in worker [EventLoopGroup].
     *
     *
     * Default value is `Runtime.getRuntime().availableProcessors() * 16`.
     *
     * @return Number of Netty worker threads
     */
    private Integer workerThreadsCount = 0;

    private boolean replyOnError;

    private boolean addLoggingHandler;

    private boolean logSensitiveData = true;

    /**
     * Returns field numbers to be treated as sensitive data.
     * Use `null` to use default ones
     *
     * Array of ISO8583 sensitive field numbers to be masked, or `null` to use default fields.
     * @see io.netty.handler.codec.LengthFieldBasedFrameDecoder
     */
    private List<Integer> sensitiveDataFields = new ArrayList<>();

    private boolean logFieldDescription = true;

    /**
     * Returns length of TCP frame length field.
     *
     *
     * Default value is `2`.
     *
     * @return Length of TCP frame length field.
     * @see io.netty.handler.codec.LengthFieldBasedFrameDecoder
     */
    private Integer frameLengthFieldLength = DEFAULT_FRAME_LENGTH_FIELD_LENGTH;

    /**
     * Returns the offset of the length field.
     *
     * Default value is `0`.
     * @see io.netty.handler.codec.LengthFieldBasedFrameDecoder
     *
     * @return The offset of the length field.
     */
    private Integer frameLengthFieldOffset = DEFAULT_FRAME_LENGTH_FIELD_OFFSET;

    /**
     * Returns the compensation value to add to the value of the length field.
     *
     *
     * Default value is `0`.
     *
     * @return The compensation value to add to the value of the length field
     * @see io.netty.handler.codec.LengthFieldBasedFrameDecoder
     */
    private Integer frameLengthFieldAdjust = DEFAULT_FRAME_LENGTH_FIELD_ADJUST;

    /**
     * If <code>true</code> then the length header is to be encoded as a String, as opposed to the default binary
     */
    private boolean encodeFrameLengthAsString;

    /**
     * Allows to add default echo message listener to [AbstractIso8583Connector].
     *
     * @return true if [EchoMessageListener] should be added to [CompositeIsoMessageHandler]
     */
    public boolean shouldAddEchoMessageListener() {
        return addEchoMessageListener;
    }
}

